package cc.idoone.spring_boot_hello.jdbc.service;

import cc.idoone.spring_boot_hello.jdbc.jpa.JpaRoleDao;
import cc.idoone.spring_boot_hello.jdbc.jpa.RoleBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @auther hemj
 * @since 2017/9/23
 */
@Service
@Transactional(value = "jpaManager")
public class JpaService {
	@Autowired
	private JpaRoleDao jpaRoleDao;

	@Transactional(readOnly = true, value = "jpaManager")
	public List<RoleBean> findAll() {
		return jpaRoleDao.findAll();
	}

	@Transactional(readOnly = true, value = "jpaManager")
	public RoleBean findRoleById(String id) {
		return jpaRoleDao.findByRoleId(id);
	}

	public RoleBean create(RoleBean role) {
		return jpaRoleDao.save(role);
	}

	public void update(RoleBean role) {
		jpaRoleDao.save(role);
	}

	public void delete(String id) {
		jpaRoleDao.delete(id);
	}
}
